﻿Imports System
Imports System.Collections.Generic
Imports System.Configuration
Imports System.Data.SqlClient
Imports System.Linq
Imports System.Web
Imports Forecast.Logica.Enumeradores
Imports Forecast.Logica.Modelos

Namespace Servicios
    Public Class ServProduct
        Public Function SearchProduct(IdEntityF As Integer, Year As Integer, IdCliente As Integer) As DataTable
            Dim cn As New SqlConnection()
            Dim cmd As New SqlCommand()
            Dim da As SqlDataAdapter
            Dim ds As DataSet

            Dim ConnString As String = ConfigurationManager.ConnectionStrings("ConnStr").ConnectionString.ToString
            cn.ConnectionString = ConnString
            cmd = New SqlCommand()
            cmd.Connection = cn
            cmd.CommandText = "FC_Product_Search"
            cmd.CommandType = CommandType.StoredProcedure

            cmd.Parameters.Add("@IdEntityF", Data.SqlDbType.Int)
            cmd.Parameters("@IdEntityF").Value = IdEntityF
            cmd.Parameters.Add("@IdSegmentPL", Data.SqlDbType.Int)
            cmd.Parameters("@IdSegmentPL").Value = Year
            cmd.Parameters.Add("@IdCliente", Data.SqlDbType.Int)
            cmd.Parameters("@IdCliente").Value = IdCliente

            da = New SqlDataAdapter()
            da.SelectCommand = cmd
            ds = New DataSet()
            da.Fill(ds)
            Return ds.Tables(0)
        End Function

        Public Function SearchProduct_DeForecast(IdEntityF As Integer, IdUsuario As Integer, _BusForecast As BusForecast) As DataTable
            Dim cn As New SqlConnection()
            Dim cmd As New SqlCommand()
            Dim da As SqlDataAdapter
            Dim ds As DataSet

            Dim ConnString As String = ConfigurationManager.ConnectionStrings("ConnStr").ConnectionString.ToString
            cn.ConnectionString = ConnString
            cmd = New SqlCommand()
            cmd.Connection = cn
            cmd.CommandText = "FC_Productos_Search_DeForecast"
            cmd.CommandType = CommandType.StoredProcedure

            cmd.Parameters.Add("@IdEntityF", Data.SqlDbType.Int)
            cmd.Parameters("@IdEntityF").Value = IdEntityF
            cmd.Parameters.Add("@IdUsuario", Data.SqlDbType.Int)
            cmd.Parameters("@IdUsuario").Value = IdUsuario
            cmd.Parameters.Add("@IdCustomer", Data.SqlDbType.Int)
            cmd.Parameters("@IdCustomer").Value = _BusForecast.IdCustomer
            cmd.Parameters.Add("@IdUOM", Data.SqlDbType.Int)
            cmd.Parameters("@IdUOM").Value = _BusForecast.IdUOM
            cmd.Parameters.Add("@IdProduct", Data.SqlDbType.Int)
            cmd.Parameters("@IdProduct").Value = _BusForecast.IdProduct
            cmd.Parameters.Add("@IdSegmento", Data.SqlDbType.Int)
            cmd.Parameters("@IdSegmento").Value = _BusForecast.IdSegmento
            cmd.Parameters.Add("@IdProductLine", Data.SqlDbType.Int)
            cmd.Parameters("@IdProductLine").Value = _BusForecast.IdProductLine
            cmd.Parameters.Add("@CodCustomer", Data.SqlDbType.VarChar)
            cmd.Parameters("@CodCustomer").Value = _BusForecast.CodCustomer

            da = New SqlDataAdapter()
            da.SelectCommand = cmd
            ds = New DataSet()
            da.Fill(ds)
            Return ds.Tables(0)
        End Function
    End Class

End Namespace
